#ifndef IC_HANDLER_H
#define IC_HANDLER_H

#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>

#include "../handler/event_handler.h"
#include "../network/i_socket.h"
#include "../network/listener.h"
#include "../model/dom.h"
#include "../network/connection_manager.h"

/** 
 * \brief This namespace includes all user-specific handlers for the iRoom.
 * \author Michael Opitz
 */
namespace user_handler {
	class ic_handler;
}

/** 
 * \brief This namespace includes all user-specific handlers for the iRoom.
 * \author Michael Opitz
 */
namespace user_handler {
	/** 
	 * \brief This class handles all messages from the microcontroller
	 */
	class ic_handler : public handler::event_handler {
	public:
		/** 
		 * \brief ic_handler creates the handler. Don't call this
		 * constructor directly, use create instead.
		 * 
		 * \param ic is the socket to the microcontroller
		 * \param web is the socket to the webinterface
		 * \param mgr is a pointer to the connection-manager.
		 */
		ic_handler(boost::shared_ptr<network::i_socket> ic, 
			   boost::shared_ptr<network::i_socket> web,
			   boost::shared_ptr<network::connection_manager> mgr)
		: _ic(ic), _web(web), _mgr(mgr) {}
		virtual ~ic_handler() {}

		/** 
		 * \brief handle_event handles all events concerning from the
		 * microcontroller.
		 * 
		 * \param n is the received message.
		 */
		virtual void handle_event(boost::shared_ptr<network::message> n);

		/** 
		 * \brief create creates the ic_handler
		 * 
		 * \see ic_handler
		 */
		static boost::shared_ptr<user_handler::ic_handler> create(
			boost::shared_ptr<network::i_socket> ic,
			boost::shared_ptr<network::i_socket> web,
			boost::shared_ptr<network::connection_manager> mgr)
		{
			boost::shared_ptr<user_handler::ic_handler> ptr(
				new user_handler::ic_handler(ic, web, mgr));
			ptr->_this = ptr;
			return ptr;
		}
	private:
		boost::shared_ptr<network::i_socket> _ic;
		boost::shared_ptr<network::i_socket> _web;
		boost::shared_ptr<network::connection_manager> _mgr;
		boost::weak_ptr<user_handler::ic_handler> _this;
	};
}

#endif
